package com.shaoshaohuo.app.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.shaoshaohuo.app.R;
import com.shaoshaohuo.app.entity.PurchaseHall;
import com.shaoshaohuo.app.utils.AreaUtil;
import com.shaoshaohuo.app.utils.StringHelper;

import java.util.List;

public class PurchaseListAdapter<T> extends MyBaseAdapter<PurchaseHall> {

	public PurchaseListAdapter(Context ctx, List<PurchaseHall> list, boolean flag) {
		super(ctx, list, flag);
	}

	@Override
	public View getView(int pos, View convertView, ViewGroup group) {
		if (convertView == null) {
			convertView = View.inflate(context, R.layout.view_caigou_list_item, null);
		}
		
		ViewHolder holder = ViewHolder.getHolder(convertView);
		
		final PurchaseHall item = list.get(pos);

		 holder.titleText.setText(item.getmName());
		 holder.subtitleText.setText(item.getcName());

		 holder.priceText.setText(item.getNum());
		 holder.priceUnitText.setText(item.getUnit());
		 holder.browserNum.setText((item.getBrowseCount() == null ? 0 : item.getBrowseCount()) +"人浏览");
		 holder.addressImage.setText(AreaUtil.getAreaFullname(item.getCityid()) + item.getAddress());
		 if(TextUtils.isEmpty(item.getEnd()) || "0".equals(item.getEnd())){
			 holder.timeText.setText("采购截止时间："+"无");
		 }else{
			 holder.timeText.setText("采购截止时间："+StringHelper.formatDateDay(item.getCursor()));
		 }
		 
		 
		return convertView;
	}

	static class ViewHolder {
		TextView titleText;
		TextView subtitleText;
		TextView priceText;
		TextView priceUnitText;
//		ImageView imageFlagImage;
//		ImageView shuaiImage;
		TextView addressImage;
		TextView timeText;
		TextView browserNum;
//		ImageView picture;
		
		public ViewHolder(View convertView){
			titleText = (TextView) convertView.findViewById(R.id.textview_name);
			subtitleText = (TextView) convertView.findViewById(R.id.textview_catname);
			priceText = (TextView) convertView.findViewById(R.id.textview_price);
			priceUnitText = (TextView) convertView.findViewById(R.id.textview_price_unit);
			addressImage = (TextView) convertView.findViewById(R.id.textview_address);
			timeText = (TextView) convertView.findViewById(R.id.textview_time);
//			holder.imageFlagImage = (ImageView) convertView.findViewById(R.id.imageview_have_image);
//			shuaiImage = (ImageView) convertView.findViewById(R.id.imageview_shuai);
			browserNum = (TextView) convertView.findViewById(R.id.tv_browser);
//			picture = (ImageView) convertView.findViewById(R.id.iv_picture);
			convertView.setTag(this);
		}
		
		public static ViewHolder getHolder(View convertView){
			return (ViewHolder) (convertView.getTag() != null ? convertView.getTag() : new ViewHolder(convertView));
		}
	}
}
